package main

import "fmt"

func main() {
	s := DaStudent{}
	s.Eat("鸡蛋")
	s.Sleep(1)
	s.Study("数学")

	// 如果要将一个结构体实例赋值给接口类型变量，需要使用指针
	var p Person = &s
	p.Eat("P-鸡蛋")
	p.Sleep(2)

	var student Student = &s
	student.Eat("student-鸡蛋")
	student.Sleep(3)
	student.Study("student-英语")
}

// Person 定义接口，接口是方法的集合
// PS:接口的所有方法必须都实现了，才算是实现了接口，少一个都不行
type Person interface {
	// Eat 吃
	Eat(food string) (bool, error)

	// Sleep 睡觉
	Sleep(hour int) (bool, error)
}

// Student 学生类型，第一层实现：Person
// Student 接口集成了Person接口所有的方法
type Student interface {
	Person
	// Study 学习
	Study(name string) (bool, error)
}

// DaStudent 学生类型。第二层实现：Student
type DaStudent struct {
}

func (s *DaStudent) Eat(food string) (bool, error) {
	fmt.Println("Eat:", food)
	return true, nil
}

func (s *DaStudent) Sleep(hour int) (bool, error) {
	fmt.Println("Sleep:", hour)
	return true, nil
}

func (s *DaStudent) Study(name string) (bool, error) {
	fmt.Println("Study:", name)
	return true, nil
}
